$(function() {

	// 下拉列表绑定（行政许可类型）
	bindDict("itemtypecode", "DM_XKXMLX", null);
})



function save() {

	var declareData = $("#declareForm").serializeObject();


	var declareMaterialData = $('#materialForm').serializeObjectArray();

	var declareMaterial = {};
	declareMaterial['dictDetail'] = 'dictDetail';
	declareMaterial['row'] = declareMaterialData;

	declareData['table'] = declareMaterial

	if (!check(declareData))
		return true;
		
	

	$.ajax({
		method : 'post',
		url : projectPath + "declare/save.do",
		data : JSON.stringify(declareData),
		dataType : "json",
		contentType : "application/json",
		success : function(data) {
	    	window.wxc.xcConfirm(data.info, window.wxc.xcConfirm.typeEnum.success, {
	    		onOk: function(){
	    			if(data.result == 1){
	    				parent.refreshData();		//刷新数据
	    			} 
	    		}
	    	});
		}
	});
}

function check(declareData){
	var result = true;
	
	if($('#tableMaterial').find('tbody').find('tr').not('.no-records-found').length == 0&&(declareData.itemtypecode!="10")){
		window.wxc.xcConfirm('请增加<span style="color:red;"><strong>行政许可材料</strong></span>的行数据！', window.wxc.xcConfirm.typeEnum.info);
		return false;
	}
	
	
	var mustStr = "itemtypecode,itemname,materialname";
	
	var strMsg = "";
	var mustStrs = mustStr.split(',');
	for(var i=0; i<mustStrs.length; i++){
		var obj = $('[name="'+mustStrs[i]+'"]');
		if(obj.val() == ""){
			strMsg += obj.attr("placeholder") + "！<br />";
			
			result = false;
		}
	}
	

	
	
	if(strMsg != ""){
		window.wxc.xcConfirm(strMsg, window.wxc.xcConfirm.typeEnum.error);
	}
	
	return result;
}

